package com.swt.gap.config;

import com.swt.gap.common.constant.UrlConstant;
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

@Data
@Component
@ConfigurationProperties(prefix = "server")
public class ServerConfig {
    /**
     * 端口号
     */
    private String port;

//    private String ip = NetUtil.getLocalhostStr();
    private String host;

    @Value("${server.servlet.context-path}")
    private String prefix;
    /**
     * 转换访问资源的url地址
     * @param fileName 资源名称
     * @param type 资源类型 1：上传的资源 2：分析结果 3：上传的icon
     * @return
     */
    public String parseViewUrl(String fileName,int type){
//        String viewUrl = "http://" + host + ":" + port;
        String viewUrl = null == prefix ? "" : prefix;

        if(1 == type){
            viewUrl = viewUrl  + UrlConstant.UPLOAD_MEDIA_URL;
        }else if (2 == type){
            viewUrl = viewUrl + UrlConstant.RESULT_URL;
        }else if(3 == type){
            viewUrl = viewUrl + UrlConstant.ICON_URL;
        }

        return viewUrl + fileName;
    }
}
